<?php

/**
 * Created by PhpStorm.
 * User: dapeng
 * Date: 2018/9/28
 * Time: 上午10:55
 */
class User
{

    //注册:添加用户
    function reg(){

        echo "进入注册";
        die();

        $user = $_POST['user'];
        $pass = $_POST['pass'];

        $sql = "insert into tb_user(name,pass) VALUES ('$user',$pass)";

        $db =    new MyPDO();
        if($db->insert($sql)){
            echo "注册成功";
        }else{
            echo "注册失败";
        }

    }

    function login(){
        echo "登录用户";
    }

    function del(){
        echo "删除用户";
    }
    //签到
    function sign(){
        echo "签到";
    }

    //当调用该对象不存在的方法,_call方法将被调用
    function __call($name, $arguments)
    {
       die("不存在该方法:".$name);
    }
    //方法返回用户的页数
    function count(){

        $pagenum = 10;//每页10条用户

        $pdo =  new MyPDO();
        $res = $pdo->select("SELECT COUNT(*) as cc FROM tb_user;");
        $page = $res[0]['cc']/$pagenum;
        //向上取整

        //返回JSON数据时,有标准的返回数据格式,方便客户端使用code进行判断
        $arr['pagecount'] = ceil($page);
        $arr['code'] = 1;
        $arr['message'] = "请求成功";
        echo json_encode($arr);
    }
}